package com.hsck.order.kds.setup.fragment

import android.app.AlertDialog
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import com.hsck.order.kds.R
import kotlinx.android.synthetic.main.dialog_tishi.view.*


class GuQingFragment : Fragment() {


    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_gu_qing, container, false)
    }

    /**
     * 取消沽清
     */
    private fun setQkDialog(data: String) {
        //R.style.***一定要写，不然不能充满整个屏宽，引用R.style.AppTheme就可以tm
        val createDialog = AlertDialog.Builder(requireActivity(), R.style.Dialog_FullScreen).create()
        // 设置Dialog的Window的软键盘模式为隐藏
        createDialog.getWindow()!!
            .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
        val view = View.inflate(requireActivity(), R.layout.dialog_tishi, null)
        val window = createDialog.getWindow()

//        window.setGravity(Gravity.BOTTOM or Gravity.RIGHT)
        //设置dialog弹出后会点击屏幕或物理返回键，dialog不消失
        createDialog.setCanceledOnTouchOutside(false)
        createDialog.setCancelable(false)
        createDialog.show()
        window!!.setContentView(view)
        window.setBackgroundDrawableResource(R.drawable.shape_grayf5_borderless20)
        //获得window窗口的属性
        val params = window.getAttributes()
        //设置窗口宽度为充满全屏
        val width = WindowManager.LayoutParams.WRAP_CONTENT
        val height = WindowManager.LayoutParams.WRAP_CONTENT
        params.width = width
        params.height = height
//        params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE//显示dialog的时候,就显示软键盘
        params.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND//就是这个属性导致window后所有的东西都成暗淡
        params.dimAmount = 0.5f//设置对话框的透明程度背景(非布局的透明度)
        //将设置好的属性set回去
        window.setAttributes(params)

        view.tv_dialog_tishi_title.text = "确认取消沽清"
        view.tv_dialog_tishi_msg.text = "取消沽清设置后，菜品可重新售卖"
        view.btn_dialog_tishi_qx.text = "取消"
        view.btn_dialog_tishi_qr.text = "确定"
        view.btn_dialog_tishi_qx.setOnClickListener {
            createDialog.dismiss()
        }
        view.btn_dialog_tishi_qr.setOnClickListener {
            createDialog.dismiss()
        }
    }

}